package com.kefu.common.redis;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.JedisPubSub;

/**
 * Redis监听订阅事件
 * @author
 *
 */
public class RedisMsgPubSubListener extends JedisPubSub {
    private static Logger logger = LoggerFactory.getLogger(RedisMsgPubSubListener.class);



    /**
     * 取得订阅的消息后的处理
     */
    @Override
    public void onMessage(String channel, String message) {
        //此处我们可以取消订阅
        if(message.equals("quit")){
            this.unsubscribe(channel);
        }
        logger.info("onMessage: channel["+channel+"], message["+message+"]");

    }
    /**
     * 取得按表达式的方式订阅的消息后的处理
     */
    @Override
    public void onPMessage(String pattern, String channel, String message) {
        logger.info("onPMessage: channel["+channel+"], message["+message+"]");

    }
    /**
     * 初始化订阅时候的处理
     */
    @Override
    public void onSubscribe(String channel, int subscribedChannels) {
        logger.info("onSubscribe: channel["+channel+"],"+
                "subscribedChannels["+subscribedChannels+"]");

    }
    /**
     * 取消订阅时候的处理
     */
    @Override
    public void onUnsubscribe(String channel, int subscribedChannels) {
        logger.info("onUnsubscribe: channel["+channel+"], "+
                "subscribedChannels["+subscribedChannels+"]");

    }
    /**
     * 取消按表达式的方式订阅时候的处理
     */
    @Override
    public void onPUnsubscribe(String pattern, int subscribedChannels) {
        logger.info("onPUnsubscribe: pattern["+pattern+"],"+
                "subscribedChannels["+subscribedChannels+"]");

    }

    /**
     * 初始化按表达式的方式订阅时候的处理
     */
    @Override
    public void onPSubscribe(String pattern, int subscribedChannels) {
        logger.info("onPSubscribe: pattern["+pattern+"], "+
                "subscribedChannels["+subscribedChannels+"]");

    }


}